export const selfMenu = [
  {
    id: 10,
    path: 'admin',
    component: 'index',
    name: '首页',
    iconCls: null,
    parentId: 0,
    enabled: 1,
    role: ['ROLE_dorm', 'ROLE_admin'],
    children: []
  },
  {
    id: 1,
    path: 'admin/ROLE_dormitory',
    component: 'ROLE_dormitory',
    name: '宿舍管理',
    iconCls: null,
    parentId: 0,
    enabled: 1,
    role: ['ROLE_admin'],
    children: [
      {
        id: 2,
        path: 'admin/building',
        component: 'building',
        name: '宿舍楼信息列表',
        iconCls: null,
        parentId: 1,
        role: ['ROLE_admin'],
        enabled: 1,
        children: []
      },
      {
        id: 3,
        path: 'admin/administrator',
        component: 'administrator',
        name: '宿舍管理员列表',
        iconCls: null,
        role: ['ROLE_admin'],
        parentId: 1,
        enabled: 1,
        children: []
      }
    ]
  },
  {
    id: 4,
    path: 'admin/health',
    component: 'health',
    name: '卫生管理',
    iconCls: null,
    parentId: 0,
    enabled: 1,
    role: ['ROLE_dorm', 'ROLE_admin'],
    children: []
  },
  {
    id: 5,
    path: 'admin/nightBelongs',
    component: 'nightBelongs',
    name: '夜归管理',
    iconCls: null,
    parentId: 0,
    enabled: 1,
    role: ['ROLE_dorm', 'ROLE_admin'],
    children: []
  },
  {
    id: 6,
    path: 'admin/maintenance',
    component: 'maintenance',
    name: '维修管理',
    iconCls: null,
    parentId: 0,
    enabled: 1,
    role: ['ROLE_dorm', 'ROLE_admin'],
    children: []
  },
  {
    id: 7,
    path: 'admin/visitor',
    component: 'visitor',
    name: '访客管理',
    iconCls: null,
    parentId: 0,
    enabled: 1,
    role: ['ROLE_dorm', 'ROLE_admin'],
    children: []
  },
  {
    id: 8,
    path: 'admin/system',
    component: 'system',
    name: '系统管理',
    iconCls: null,
    parentId: 0,
    enabled: 1,
    role: ['ROLE_admin'],
    children: []
  },
  {
    id: 9,
    path: 'admin/password',
    component: 'password',
    name: '修改密码',
    iconCls: null,
    parentId: 0,
    enabled: 1,
    role: ['ROLE_dorm', 'ROLE_admin'],
    children: []
  }
]
// 1要跳转到首页后默认打开某页面
const firstMenu: any = null
export function pathMapToMenu (Menus: any[], currentPath: string): any {
  for (const menu of Menus) {
    if (menu.children.length > 0) {
      const findMenu = pathMapToMenu(menu.children ?? [], currentPath)
      if (findMenu) {
        return findMenu
      }
    } else if (menu.children.length === 0 && '/' + menu.path === currentPath) {
      return menu
    }
  }
}
// 3导出，在导航守卫使用
export { firstMenu }

export const formatDateTime = (date:string):string => {
  const dateTime = new Date(date)
  const y = dateTime.getFullYear()
  let m = dateTime.getMonth() + 1
  m = m < 10 ? (0 + m) : m
  let d = dateTime.getDate()
  d = d < 10 ? (0 + d) : d
  let h = dateTime.getHours()
  h = h < 10 ? (0 + h) : h
  let minute = dateTime.getMinutes()
  minute = minute < 10 ? (0 + minute) : minute
  let second = dateTime.getSeconds()
  second = second < 10 ? (0 + second) : second
  return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second
}
